﻿using UnityEngine;
using System.Collections;

public class Menu : MonoBehaviour {

	public GameObject item;
	public Transform itemPosition;

    /// <summary>
    /// Updates this instance. Called once per frame
    /// </summary>
    void Update()
    {
        Screen.showCursor = true;
    }

    /// <summary>
    /// Called when [mouse enter].
    /// </summary>
	void OnMouseEnter(){
		Instantiate(item, itemPosition.position, itemPosition.rotation);
        GetComponentInChildren<TextMesh>().color = Color.cyan;
	}

    /// <summary>
    /// Called when [mouse exit].
    /// </summary>
	void OnMouseExit(){
		Destroy (GameObject.Find(item.name + "(Clone)"));
		GetComponentInChildren<TextMesh>().color = Color.white;
	}

    /// <summary>
    /// Called when [mouse up].
    /// </summary>
	void OnMouseUp(){

        // Control the menu item and load the right level when the player click on one button

		if (gameObject.name == "OnePlayer") {
			Application.LoadLevel("onePlayerGame");
		}
        if (gameObject.name == "TwoPlayers")
        {
            Application.LoadLevel("twoPlayersGame");
        }
		if(gameObject.name == "Quit"){
			Application.Quit();
		}
		if (gameObject.name == "Options") {
			Application.LoadLevel("options");
		}
        if (gameObject.name == "Return")
        {
            Application.LoadLevel("menu");
        }
	}

}
